package com.wx.mythread.thread;

public class MethodSychroize2 implements Runnable {
    private static MethodSychroize2 methodSychroize2= new MethodSychroize2();
    @Override
    public void run() {
        method();
    }

    public synchronized void method(){
        System.out.println("我是对象锁的方法修饰符，我叫"+Thread.currentThread().getName()+"开始");
        try {
            Thread.sleep(3000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("我是对象锁的方法修饰符，我叫"+Thread.currentThread().getName()+"结束");
    }

    public static void main(String[] args) {
        Thread thread1 = new Thread(methodSychroize2);
        Thread thread2 = new Thread(methodSychroize2);
        thread1.start();
        thread2.start();
        while (thread1.isAlive() || thread2.isAlive()){

        }
        System.out.println("game over!");
    }
}
